package Fangfalianxi;

import java.util.Scanner;

//评委打分
//需求：在唱歌比赛中，有6位评委给选手打分，分数范围是[0-100]之间的整数。选手的最后得分为：去掉最高分、最低分的4个评委的平均分，
//     计算出选手的分数。
public class test5 {
    public static void main(String[] args) {
        int[] scoresArr = scores();
        for (int i = 0; i < scoresArr.length; i++) {
            System.out.println(scoresArr[i]);
        }
        int max = getmax(scoresArr);
        int min = getmin(scoresArr);
        int sum = getsum(scoresArr);
        int avg = 0;
        avg = (sum - max - min)/(scoresArr.length-2);
        System.out.println("选手得分为："+avg);

    }

    public static int getsum(int[] scoresArr){
        int sum = 0;
        for (int i = 0; i < scoresArr.length; i++) {
            sum  = sum + scoresArr[i];
        }
        return sum;
    }

    public static int getmax(int[] scoresArr){
        int max = scoresArr[0];
        for (int i = 0; i < scoresArr.length; i++) {
            if(max < scoresArr[i]){
                max = scoresArr[i];
            }
        }
        return max;
    }

    public static int getmin(int[] scoresArr){
        int min = scoresArr[0];
        for (int i = 0; i < scoresArr.length; i++) {
            if(min < scoresArr[i]){
                min = scoresArr[i];
            }
        }
        return min;
    }

    public static int[] scores(){
        int[] scores = new int[6];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 6; ) {
            System.out.println("请输入评委打的分：");
            int score = sc.nextInt();
            if(score>=0 && score<=100){
                scores[i] = score;
                i++;
            }else{
                System.out.println("成绩超出范围，请重新输入，当前的i为："+i);
            }
        }
        return scores;
    }
}
